<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intLID = (int)$data["LottoID_n"];

//設置新增彩期旗標
$strFlag = "AddCompetition".$intLID;
setFlagToDB($strFlag, 15);

$strSQL = "select * from `bet_Gamble` where isEnd = 0 and LottoID = ".$intLID;
if(!$RS = PMA_mysql_query($strSQL, $_ConnMaster)){
	$GLOBALS["errormessage"] = "Find Game Data Error!!";
	$GLOBALS["errorhidden"] = "\nError: ".PMA_mysql_error($_ConnMaster).",\nLine: ".__LINE__.",\nPage: ".__FILE__;
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error", "", 1);
}

if(PMA_mysql_num_rows($RS) > 0){
	$arrD = array();
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrD[] = $Rows -> GameDate;
	}
	$GLOBALS["errormessage"] = join(", ", $arrD).$_strCompetition["unCount"];
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error", "", 1);
}

$isErr = true;
$Y = explode("-",$data["GameDate_x"]);
$H = explode(":",$data["GameTime_x"]);
$arrET = explode(":",$data["EndGameTime_x"]);
$arrETSN = explode(":",$data["EndGameTimeSN_x"]);
if(!checkdate($Y[1], $Y[2], $Y[0])){
	$GLOBALS["errormessage"] = $_strCompetition["DateError"];//"賽程日期格式錯誤！";
}elseif(!is_array($H) || sizeof($H) != 3 || $H[0] < 0 || $H[0] > 23 || $H[1] < 0 || $H[1] > 59){
	$GLOBALS["errormessage"] = $_strCompetition["TimeError"];//"賽程時間格式錯誤！";
}elseif(!is_array($arrET) || sizeof($arrET) != 3 || $arrET[0] < 0 || $arrET[0] > 23 || $arrET[1] < 0 || $arrET[1] > 59){
	$GLOBALS["errormessage"] = $_strCompetition["TimeError"];//"賽程時間格式錯誤！";
}elseif(!is_array($arrETSN) || sizeof($arrETSN) != 3 || $arrETSN[0] < 0 || $arrETSN[0] > 23 || $arrETSN[1] < 0 || $arrETSN[1] > 59){
	$GLOBALS["errormessage"] = $_strCompetition["TimeError"];//"賽程時間格式錯誤！";
}else{
	$isErr = false;
}

if($isErr){
	$GLOBALS["errorhidden"] = "\nLine: ".__LINE__.",\nPage: ".__FILE__;
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error", "", 1);
}

$data["LottoID_n"] = $intLID;
$data["SerialNo_x"] = (float)$data["SerialNo_n"];
$data["OSerialNo_x"] = (float)$data["OSerialNo_n"];
unset($data["SerialNo_n"]);
unset($data["OSerialNo_n"]);
$data["PayupDate_x"] = $data["GameDate_x"];
$data["GameDate_x"] = DateForm($data["GameDate_x"], $data["GameTime_x"], "Y-m-d", "CToU");
$data["GameTime_x"] = TimeForm($data["GameDate_x"], $data["GameTime_x"], "H:i:s", "CToU");
$data["EndGameTime_x"] = TimeForm($data["GameDate_x"], $data["EndGameTime_x"], "H:i:s", "CToU");
$data["EndGameTimeSN_x"] = TimeForm($data["GameDate_x"], $data["EndGameTimeSN_x"], "H:i:s", "CToU");

//刪除過期賠率表資料
if(!DeleteTodayGame(0, $intLID)){
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error1", "", 1);
}

//將此期樂透狀態，改為已結束
if(!setGameEnd($intLID)){
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error2", "", 1);
}

//刪除已結帳過期注單
if(!rmCompetitionEndLastDayData()){
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error3", "", 1);
}

if(!$intGID = InsertSQL($data, "`bet_Gamble`")){
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error4", "", 1);
}
if(!InsertPreOdds($intLID, $intGID)){
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error5", "", 1);
}
if(!MakeGambleFile($intLID)){
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error6", "", 1);
}

if(!makeShowScoreFile($intLID, "", "", "")){
	//移除新增彩期旗標
	delFlagToDB($strFlag);
	ErrMsgOutputHTML("Error7", "", 1);
}

//移除新增彩期旗標
delFlagToDB($strFlag);

@mysql_close($$_Conn);
header("Location: ".basename($_SERVER["PHP_SELF"])."?op=List&GameDate=".$_data["GameDate"]);
?>
